package lab03.test08;

import java.io.*;

/**
 * Created by 星月 on 2017/12/09.
 */
public class Test08 {
    public static void main(String[] args) {
        //定义文件路径
        File file=new File("F:\\java实验三\\helloworld.txt");
        String path1="F:\\java实验三\\hello.txt";
        String path2="F:\\java实验三\\world.txt";

        //定义文件1和文件2的输入流
        FileInputStream fileInputStream1=null;
        FileInputStream fileInputStream2=null;
        //定义文件3的输入流
        FileOutputStream fileOutputStream=null;
        try {
            fileInputStream1=new FileInputStream(path1);
            fileInputStream2=new FileInputStream(path2);
            fileOutputStream=new FileOutputStream(file);
            int data1=0;
            int data2=0;
            while (true){
                    if (((data1=fileInputStream1.read())!=-1)&&((data2=fileInputStream2.read())!=-1)){
                        fileOutputStream.write(data1);
                        fileOutputStream.write(data2);
                    }
                    else if (((data1=fileInputStream1.read())==-1)&&((data2=fileInputStream2.read())!=-1)){
                        fileOutputStream.write(data2);
                    }else if (((data1=fileInputStream1.read())!=-1)&&((data2=fileInputStream2.read())==-1)){
                        fileOutputStream.write(fileInputStream1.read());
                    }else
                        break;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
